﻿@model ProfileViewModel
@using Devonline.AspNetCore;
@inject Microsoft.AspNetCore.Http.IHttpContextAccessor _httpContextAccessor;
@{
    ViewData["Title"] = "用户主页";
    var isExternal = false;
    var clientUri = string.Empty;
    var clientName = string.Empty;
    if (Model is not null)
    {
        isExternal = true;
        Layout = "_LayoutUnAuth";
        clientUri = Model.ClientUri;
        clientName = Model.ClientName;
    }

    var name = _httpContextAccessor.HttpContext?.User?.Identity?.Name;
    var userId = _httpContextAccessor.HttpContext?.GetUserId();
}

@if (@isExternal)
{
    <header id="_header_" class="header body-content">
        <nav class="navbar navbar-default header-navigation">
            <a class="navbar-brand" href="@clientUri">
                <img src="~/icons/identity.png"> @clientName
            </a>

            <ul class="nav navbar-nav navbar-right user-info">
                <li class="nav-item">
                    <a class="nav-link text-dark" href="">[@name]</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link text-dark" href="@clientUri">[ 返回 ]</a>
                </li>
            </ul>
        </nav>
    </header>
}

<div id="_profile_detail_panel" class="col-md-4 col-md-offset-2">
    <div class="panel panel-default">
        <div class="form-content" data-toggle="form" data-field="UserDetail" data-side="server" data-url="/api/UserProfile" data-detailable="true" data-size="12,4,8" data-loaded="#:Profile.onLoad" data-bound="#:Profile.onBound">
            <div class="form-heading">
                基本信息
                <div class="pull-right">
                    <button data-button="edit" data-clicked="#:Profile.onEdit"></button>
                </div>
            </div>
            <div class="form-body">
                <div data-field="image" data-title="用户图片" data-type="img" data-with-attachments="true" data-business-type="User.Image" data-single="true"></div>
                <span data-field="userName" data-title="用户名"></span>
                <span data-field="name" data-title="姓名"></span>
                <span data-field="alias" data-title="别名"></span>
                <span data-field="phoneNumber" data-title="手机号码" data-size="12,4,6"></span>
                <span data-field="email" data-title="电子邮件" data-size="12,4,6"></span>
                <span data-field="description" data-title="备注说明"></span>
            </div>

            @*<div class="form-heading">
            联系方式
            </div>
            <div class="form-body">
            <span data-field="phoneNumber" data-title="手机号码" data-size="12,4,6"></span>
            <span data-field="email" data-title="电子邮件" data-size="12,4,6"></span>
            </div>*@
        </div>
    </div>
</div>

<div id="_profile_edit_panel" class="col-md-4 col-md-offset-2">
    <div class="panel panel-default">
        <div class="form-content" data-toggle="form" data-field="UserEdit" data-editable="true" data-ignore-fields="PhoneNumber,Email">
            <div class="form-heading">
                编辑您的个人信息
                <div class="pull-right">
                    <button data-button="back" data-action="#:Profile.onBack"></button>
                </div>
            </div>
            <div class="form-body">
                <span data-field="userName" data-title="用户名"></span>
                <input data-field="name" data-title="姓名" required />
                <input data-field="alias" data-title="别名" />
                <input data-field="phoneNumber" data-title="手机号码" />
                <input data-field="email" data-title="电子邮件" />
                <textarea data-field="description" data-title="备注说明" rows="3" data-multiple="true"></textarea>
                <input data-field="image" data-title="用户图片" data-with-attachments="true" data-business-type="User.Image" data-single="true" type="file" data-role="kendoUpload" data-file-size="1024" data-file-extension=".jpg,.jpeg,.png" />
            </div>

            <div class="form-footer col-md-offset-3">
                <button data-button="submit" data-url="/api/UserProfile" data-complete="#:Profile.onEditSuccess"></button>
            </div>
        </div>

        @* <div class="form-content">
        <div class="form-heading">
        联系方式
        </div>
        <div class="form-body">
        <div data-toggle="form" data-field="UserPhoneNumber" data-url="/api/UserProfile/ChangePhoneNumber">
        <input type="hidden" data-field="userName" />
        <input type="hidden" data-field="token" />
        <input id="_txt_edit_phoneNumber" data-field="phoneNumber" data-title="手机号码" data-readonly="true" data-size="12,3,6" />
        <button id="_btn_edit_phoneNumber" data-button="edit" data-clicked="#:Profile.onEditPhoneNumber" class="field-group-button"></button>
        <button id="_btn_submit_phoneNumber" data-button="submit" data-display="false" data-complete="#:Profile.onAfterEditPhoneNumber" class="field-group-button"></button>
        </div>
        <div data-toggle="form" data-field="UserEmail" data-url="/api/UserProfile/ChangeEmail">
        <input type="hidden" data-field="userName" />
        <input type="hidden" data-field="token" />
        <input id="_txt_edit_email" data-field="email" data-title="电子邮件" data-readonly="true" data-size="12,3,6" />
        <button id="_btn_edit_email" data-button="edit" data-clicked="#:Profile.onEditEmail" class="field-group-button"></button>
        <button id="_btn_submit_email" data-button="submit" data-display="false" data-complete="#:Profile.onAfterEditEmail" class="field-group-button"></button>
        </div>
        </div>
        </div>*@
    </div>
</div>

<div id="_changePassword_panel" class="col-md-4">
    <div class="panel panel-default">
        <div class="form-content" data-toggle="form" data-field="ChangePassword" data-editable="true" data-size="12,4,7">
            <div class="form-heading">
                修改密码
            </div>
            <div class="form-body">
                <input id="ChangePassword_userName" type="hidden" data-field="userName" data-title="用户名" />
                <input type="password" data-field="password" data-title="原始密码" required />
                <input type="password" data-field="newPassword" data-title="新密码" required />
                <input type="password" data-field="confirmNewPassword" data-title="确认新密码" required />
            </div>
            <div class="form-footer col-md-offset-4">
                <button data-button="submit" data-url="/api/UserProfile/ChangePassword" data-before-submit="#:Profile.onBeforeChangePassword"></button>
            </div>
        </div>
    </div>
</div>

<script src="~/js/profile.js" asp-append-version="true"></script>